//
//  YFCityPartnerCell.m
//  QuanJieShopProject
//
//  Created by apple on 2018/5/26.
//  Copyright © 2018年 apple. All rights reserved.
//

#import "YFCityPartnerCell.h"


@implementation YFCityPartnerModel
- (instancetype)initWithTitle:(NSString *)title imgStr:(NSString *)imgStr {
    YFCityPartnerModel *model = [[YFCityPartnerModel alloc] init];
    model.title = title;
    model.imgStr = imgStr;
    return model;
}
@end

@interface YFCityPartnerCell ()
@property (nonatomic, strong) UIImageView *imgView;
@property (nonatomic, strong) UILabel *nameLabel;
@property (nonatomic, strong) UIView *line;
@end


@implementation YFCityPartnerCell

+ (instancetype)cellWithTableView:(UITableView *)tableView {
    static NSString *cellID = @"YFCityPartnerCellID";
    YFCityPartnerCell *cell = [tableView dequeueReusableCellWithIdentifier:cellID];
    if (!cell) {
        cell = [[YFCityPartnerCell alloc] initWithStyle:UITableViewCellStyleDefault reuseIdentifier:cellID];
        cell.selectionStyle = UITableViewCellSelectionStyleNone;
    }
    return cell;
}

- (instancetype)initWithStyle:(UITableViewCellStyle)style reuseIdentifier:(NSString *)reuseIdentifier {
    if (self = [super initWithStyle:style reuseIdentifier:reuseIdentifier]) {
        self.backgroundColor = [UIColor whiteColor];
        [self makeView];
    }
    return self;
}

- (void)makeView {
    
    // 分割线
    UIView *line = [[UIView alloc] init];
    line.backgroundColor = [UIColor colorWithHexString:@"f5f5f5"];
    [self addSubview:line];
    self.line = line;
    
    // 图片
    UIImageView *imgView = [[UIImageView alloc] init];
    imgView.image = [UIImage imageNamed:@"noImage"];
    [self addSubview:imgView];
    self.imgView = imgView;
    
    // 名字
    UILabel *nameLabel = [[UILabel alloc] init];
    //    nameLabel.text = @"¥1222.22";
    nameLabel.textColor = [UIColor colorWithHexString:@"333333"];
    nameLabel.font = [UIFont systemFontOfSize:16];
    nameLabel.numberOfLines = 2;
    [self.contentView addSubview:nameLabel];
    self.nameLabel = nameLabel;
    
    [self.line mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.left.right.equalTo(self);
        make.height.equalTo(@(10));
    }];
    
    [self.nameLabel mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self.imgView.mas_right).with.offset(10);
        make.right.equalTo(self.mas_right).with.offset(-10);
        make.top.equalTo(self.line.mas_bottom);
        make.bottom.equalTo(self.mas_bottom);
    }];
    
    
    [self.imgView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.left.equalTo(self).with.offset(10);
        make.width.height.equalTo(@(20));
        make.centerY.equalTo(self.nameLabel);
    }];
    
}


- (void)setModel:(YFCityPartnerModel *)model {
    _model = model;
    
    self.imgView.image = [UIImage imageNamed:model.imgStr];
    self.nameLabel.text = model.title;
    
}

@end
